package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbProvincesMapper;
import com.bw1806.pojo.TbProvinces;
import com.bw1806.pojo.TbProvincesExample;
import com.bw1806.sellergoods.service.TbProvincesService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbProvincesServiceImpl implements TbProvincesService {

    @Autowired
    private TbProvincesMapper tbProvincesMapper;

    @Override
    public List<TbProvinces> findAll() {
        return tbProvincesMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbProvinces> pagelist(TbProvinces tbProvinces,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbProvincesExample example=new TbProvincesExample();

        TbProvincesExample.Criteria criteria = example.createCriteria();

        if(tbProvinces!=null){
            //if(tbProvinces.getName()!=null && tbProvinces.getName().length()>0){
            //    criteria.andNameLike("%"+tbProvinces.getName()+"%");
           // }
        }

        Page<TbProvinces> page= (Page<TbProvinces>) tbProvincesMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbProvinces tbProvinces) {
        Long id = tbProvinces.getId();
        if(id != null && id !=0){
            tbProvincesMapper.updateByPrimaryKey(tbProvinces);
        } else{
            tbProvincesMapper.insert(tbProvinces);
        }
    }

    @Override
    public TbProvinces getById(Long id) {
        return tbProvincesMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbProvincesMapper.deleteByPrimaryKey(id);
        }
        //tbProvincesMapper.deletebth(ids);
    }
}
